package controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import model.BookmarkDAO;
import model.Model;

import org.mybeans.form.FormBeanFactory;

import formBean.RedirectForm;

public class ManageRedirectAction extends Action {

	private FormBeanFactory<RedirectForm> formBeanFactory = FormBeanFactory.getInstance(RedirectForm.class);
	BookmarkDAO bookmarkDAO;
	
	public ManageRedirectAction(Model model){
		bookmarkDAO = model.getBookmarkDAO();
	}
	
	
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "manageRedirect.do";
	}

	@Override
	public String perform(HttpServletRequest request) {
		List<String> errors = new ArrayList<String>();
        request.setAttribute("errors",errors);
        try{
	    	RedirectForm form = formBeanFactory.create(request);
	        request.setAttribute("form",form);
	        request.setAttribute("redirectURL", form.getUrl());
	        return "redirect.jsp";
        }catch(Exception e){
        	return "error.jsp";
        }
	}
}
